package xtu.www.common.router.rule;

import android.content.Context;
import android.content.Intent;

import java.util.TreeMap;

/**
 * Created by huilin on 2017/6/15.
 */

public class BaseRule<T> implements Rule<T, Intent> {
    TreeMap<String, Class<T>> treeMap = new TreeMap<>();

    @Override
    public void router(String pattern, Class<T> tClass) {
        treeMap.put(pattern, tClass);
    }

    @Override
    public Intent invoke(Context context, String pattern) {
        Class<T> tClass = treeMap.get(pattern);
        if (tClass == null) {
            throw new IllegalArgumentException("no find class");
        }
        return new Intent(context, tClass);
    }


}
